package cn.wolfcode.rocketmq._03_consumer_type;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;

import java.util.List;

public class Consumer {

    public static void main(String[] args) throws Exception {
        //创建消费者对象
        DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer("consumer-demo");
        //绑定nameserver地址
        defaultMQPullConsumer.setNamesrvAddr("localhost:9876");
        //启动消费者
        defaultMQPullConsumer.start();
        PullResult pull = defaultMQPullConsumer.pull(new MessageQueue("consumer-type", "broker-a", 0), "*", 0, 10);
        List<MessageExt> msgFoundList = pull.getMsgFoundList();
        for (MessageExt messageExt : msgFoundList) {
            System.out.println("消息的内容为:"+new String(messageExt.getBody()));
        }
    }
}
